package com.example.administrator.printoutindemo.popupwin;


import android.app.Activity;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.PopupWindow;

import com.example.administrator.printoutindemo.R;


public class PopupwinSelectInventory extends PopupWindow{

	private View mMenuView;

	public PopupwinSelectInventory(Activity context,OnClickListener itemOnclick) {

		super(context);

		LayoutInflater inflater = (LayoutInflater)
				context.getSystemService(context.LAYOUT_INFLATER_SERVICE);

		mMenuView = inflater.inflate(R.layout.popupwin_select_inventory, null);


		//设置SelectPicPopupWindow的View
		this.setContentView(mMenuView);
		//设置SelectPicPopupWindow弹出窗体的宽
		this.setWidth(LayoutParams.MATCH_PARENT);
		//设置SelectPicPopupWindow弹出窗体的高
		this.setHeight(LayoutParams.WRAP_CONTENT);
		//设置SelectPicPopupWindow弹出窗体可点击
		this.setFocusable(true);
		//设置SelectPicPopupWindow弹出窗体动画效果
		//this.setAnimationStyle(R.style.AnimBottom);
		//实例化一个ColorDrawable颜色为半透明
		ColorDrawable dw = new ColorDrawable(0xb0000000);
		//设置SelectPicPopupWindow弹出窗体的背景
		this.setBackgroundDrawable(dw);


		mMenuView.setOnTouchListener(new OnTouchListener() {

			@Override
			public boolean onTouch(View v, MotionEvent event) {
				// TODO Auto-generated method stub

				int height = mMenuView.findViewById(R.id.pop_layout).getTop();
				int y = (int)event.getY();

				if(event.getAction()==MotionEvent.ACTION_UP){

					if (y < height) {
						dismiss();
					}
				}

				return false;
			}
		});
	}
}